* --------------------------- Table 12: Establishing relationships with new BDCs
use "$data_path/database_company_level_synthetic", clear 

gen treated = ind_treated_company
gen interaction = ind_post*treated 

reghdfe new_bdc_relationship ind_post treated interaction company_time_fe lag_assets_total_ln lag_debt_to_assets_ratio lag_int_inc_net_avg_assets, noabsorb vce(cluster company_all_num)
estadd local company_time_fe "Yes"
estadd local controls "Yes"
estimates store preg_a

// for borrowers that were kept by affected BDCs
drop treated interaction
gen ind_treated_kept = ind_treated_company*ind_treated_borrower_kept
replace ind_treated_kept = . if ind_treated_company == 1 & ind_treated_borrower_kept == 0
gen treated = ind_treated_kept
gen interaction = ind_post*ind_treated_kept

reghdfe new_bdc_relationship ind_post treated interaction company_time_fe lag_assets_total_ln lag_debt_to_assets_ratio lag_int_inc_net_avg_assets, noabsorb vce(cluster company_all_num)
estadd local company_time_fe "Yes"
estadd local controls "Yes"
estimates store preg_b

// for borrowers that were NOT kept by affected BDCs
drop treated interaction
gen ind_treated_dropped = ind_treated_company*(1-ind_treated_borrower_kept)
replace ind_treated_dropped = . if ind_treated_company == 1 & ind_treated_borrower_kept == 1
gen treated = ind_treated_dropped
gen interaction = ind_post*ind_treated_dropped

reghdfe new_bdc_relationship ind_post treated interaction company_time_fe lag_assets_total_ln lag_debt_to_assets_ratio lag_int_inc_net_avg_assets, noabsorb vce(cluster company_all_num)
estadd local company_time_fe "Yes"
estadd local controls "Yes"
estimates store preg_c


esttab preg_a preg_b preg_c    ///
using "${tables_path}/table12.tex" ///
,cells(b(star  fmt(2)) se(par  fmt(2))) stat(company_time_fe controls r2 N, fmt(%~15s %~15s %9.2g %9.0g ) layout(\mc{@} \mc{@}  @ \mc{@}) labels("$\reallywidehat{\text{Firm-Time FE}}$" "BDC-Level Controls" "\$R^{2}\$" "\textit{N}")) ///
style(tex) starlevels(^{*} 0.10  ^{**} 0.05 ^{***} 0.01)  mtitles("(1)" "(2)" "(3)")  nonumbers noomitted  collabels(none) ///
coeflabels(company_time_fe "Firm-Time FE" ind_post "Post" treated "Treated Firm" interaction "Post \$\times\$ Treated Firm" lag_debt_to_assets_ratio "\$\overline{\text{Debt/Assets}}_{t-1}\$" lag_assets_total_ln "\$\overline{\text{ln(Assets}_{t-1}\text{)}}\$" lag_int_inc_net_avg_assets "\$\overline{\text{Net Int. Inc./Assets}}_{t-1}\$" ) ///
order(ind_post treated interaction) keep(ind_post treated interaction) replace substitute(\_ _) noomit nobaselevels alignment(D{.}{.}{-1})  tex ///
nolines prefoot(\midrule) postfoot(\bottomrule \end{tabular} }) posthead(\midrule)
 
